﻿using System.Data.Entity;
using AutoClub.Core.Domain.Dao;
using System.Data.Entity.Validation;

namespace AutoClub.Core.Dao
{
    /// <summary>
    /// Unit of Work implemented with EF4 for Auto Club Pigue
    /// </summary>
    public class AutoClubUnitOfWork : IUnitOfWork
    {
        #region Constructor

        public AutoClubUnitOfWork()
        {
            this.Context = new AutoClubDataContext();
        }

        #endregion

        /// <summary>
        /// Persists the database changes
        /// </summary>
        public void Commit()
        {
            try
            {
                this.Context.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                throw;
            }
            
        }

        public DbContext Context
        {
            get;
            private set;
        }

        public void Dispose()
        {
            this.Context.Dispose();
        }
    }
}
